/* 
 * @description: 日历组件
 * @author: Jane 
 * @date: 2023-10-17 10:24:27
 */
import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:table_calendar/table_calendar.dart';
class CalendarWidget extends StatefulWidget {
  const CalendarWidget({super.key});
  @override
  State<CalendarWidget> createState() => _CalendarWidgetState();
}
class _CalendarWidgetState extends State<CalendarWidget> {
  DateTime? _selectedDay;
  DateTime? _focusedDay;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: TableCalendar(
        locale: 'zh_CN',
        firstDay: DateTime.utc(2023, 10, 1),
        lastDay: DateTime.utc(2030, 3, 14),
        focusedDay: DateTime.now(),
        startingDayOfWeek: StartingDayOfWeek.sunday, //从周几开始
        shouldFillViewport: false, // 整页显示
        calendarFormat: CalendarFormat.twoWeeks, // 显示周日历 还是月日历
        calendarStyle: CalendarStyle(
            outsideDaysVisible: false,
            todayTextStyle: TextStyle(color: AppTheme.bluetextColor),
            outsideTextStyle: TextStyle(color: AppTheme.weakTextColor),
            todayDecoration: BoxDecoration(
                color: AppTheme.bluetextColor.withOpacity(.2),
                shape: BoxShape.rectangle),
            selectedDecoration: BoxDecoration(
                color: AppTheme.bluetextColor.withOpacity(.2),
                shape: BoxShape.rectangle),
            selectedTextStyle: TextStyle(color: AppTheme.bluetextColor),
            weekNumberTextStyle: TextStyle(color: AppTheme.weakTextColor),
            rangeStartTextStyle: TextStyle(color: AppTheme.weakTextColor)),
        headerStyle: HeaderStyle(
            titleCentered: true,
            formatButtonVisible: false,
            titleTextStyle: TextStyle(color: AppTheme.bluetextColor),
            headerPadding:
                EdgeInsets.symmetric(horizontal: ScreenHelper.width(70)),
            // headerMargin:
            //     EdgeInsets.symmetric(horizontal: ScreenHelper.width(70)),
            decoration: BoxDecoration(color: Colors.blue.withOpacity(.1))),
        selectedDayPredicate: (day) {
          return isSameDay(_selectedDay, day);
        },
        onDaySelected: (selectedDay, focusedDay) {
          setState(() {
            _selectedDay = selectedDay;
            _focusedDay = focusedDay; // update `_focusedDay` here as well
          });
        },
      ),
    );
  }
}
